var app = angular.module("myApp",[]);
app.controller("myCtrl",function($scope,$http,$timeout){
	$scope.no = false;                 //错误提示框
	$scope.password0 = "";             //用户密码
	$scope.password1 = ""              //再次确认
	$scope.img_code = "";              //图片验证码
	
	//获取图片验证码
	$scope.src = host + "/terminal/verificationCode/generate";
	
	//修改密码
	$scope.change = function(){
		if(!/^[a-zA-Z0-9_\-$]{6,18}$/.test($scope.password0)){
			$scope.no = true; 
			$scope.message = "密码格式不正确";
			$timeout(function(){
        		$scope.no = false;
        	},750);
			return;
		}
		if($scope.password0 != $scope.password1){
			$scope.no = true; 
			$scope.message = "输入的密码不一样";
			$timeout(function(){
        		$scope.no = false;
        	},750);
			return;
		}
		var params={
			verificationCode : $scope.img_code,
			password : $scope.password0
		};
		params = $.param(params);
		$http({
        	method : "post",
        	dataType: "json",
			withCredentials: true,	//跨域名请求。XHR：XMLHttpRequest (XHR) ，基于XML技术的Http请求
	        headers:{'Content-Type': 'application/x-www-form-urlencoded'},
	        crossDomain: true,
	        data : params,
        	url : host + "/terminal/user/changePW"
        }).success(function(response){
        	console.log(response);
        	if(response.code == 4003){
        		$scope.no = true; 
				$scope.message = response.message;
				$timeout(function(){
	        		$scope.no = false;
	        	},750);
        	}
        	if(response.code == 2000){
        		console.log(response);
        		$scope.no = true; 
				$scope.message = response.message;
				$timeout(function(){
	        		$scope.no = false;
	        	},1250);
        	}
        })
	}
})